<?php
/**
 * @Author:      lyt
 * @DateTime:  2017-05-16 15:39:55
 * @Description: 用于充值记录的消费记录
 */
class AcountUserRechargeSpend extends Eloquent
{
    protected $table = "acount_user_recharge_spend_record";


    /**
     * @Author:      lyt
     * @DateTime:  2017-05-22 14:22:52
     * @Description: 获取一个余额额退款 支付记录需要的 充值消费记录
     * @param $buss_id 业务id
     * @param $order_amount 金额
     * @param $type 业务类型
     */
    public static function getUseRecharge($buss_id,$order_amount,$type){        
        $finally_arr=array();        
        //获取 未使用完的支付记录
        $s_aur=AcountUserRechargeSpend::where("buss_id",$buss_id)->where("type",$type)->where("status",1)->orderBy("id","desc")->get();
        foreach ($s_aur as $_s_aur) {
        	$aur=AcountUserRecharge::find($_s_aur->aurr_id);
        	$uad=UserAccountDeatails::find($aur->account_no);
        	$_s_aur->acount_type=$uad->acount_type;
        	if(($_s_aur->amount-$_s_aur->return_amount)>=$order_amount){//说明这次充值记录满足需求
	    		$_s_aur->user_amount=$order_amount;
	    		$finally_arr[]=$_s_aur;
	    		return $finally_arr;
	    	}else{//说明 这次不满足需求
	    		$_s_aur->user_amount=($_s_aur->amount-$_s_aur->return_amount);	    		
	    		$order_amount=$order_amount-$_s_aur->user_amount;
	    		$finally_arr[]=$_s_aur;
	    	}
        }    
        //如果都不满足说明数据支付过程中 修改  拒绝支付
        return array();
   
    }
    
        /**
         * @Author:      zy
         * @DateTime:  2017-07-14 09:34:59
         * @Description: 洗车单支付统计
         */
        public static function spendMoney($shop_id,$start_time,$end_time){
            $record = DB::select("SELECT a.id,a.aurr_id,sum(a.amount) AS amount
                FROM  acount_user_recharge_spend_record as a
                LEFT JOIN car_wash_order_pay_record b ON a.buss_id = b.id
                LEFT JOIN car_wash_order c ON c.order_id = b.order_id 
                WHERE c.shop_id = ? AND c.pay_time  BETWEEN ? AND ? 
                AND c.`status` = 1417 and a.type=2 and b.pay_type=8 group by a.id",
                array($shop_id,$start_time,$end_time));
            return $record;
        }
}